package crud.client.data;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;

import com.google.gwt.user.client.rpc.IsSerializable;

import crud.client.annotation.DisplayValue;
import crud.client.annotation.Email;
import crud.client.annotation.FieldValidatorFactory;
import crud.client.annotation.Label;
import crud.client.annotation.MultipleValue;
import crud.client.annotation.Parameter;
import crud.client.annotation.TableValidatorFactory;
import crud.client.factory.SexeRadioGroupFactory;
import crud.client.factory.validator.field.RegExValiatorFactory;
import crud.client.validator.PersonneGenreValidatorFactory;

@Entity(name="PERSONNE")

public class Personne implements Serializable, IsSerializable
{
	@Id
	@Column(name="PERSONNE_ID")
	@Label(value="Identifiant")
	private Integer personneId;

	@Column(name="CODE_CIVILITE", nullable = false)
	@MultipleValue(values={"1=MR", "2=MME", "3=MLLE"})
	@Label(value="Civilit&eacute;")
	private String codeCivilite;
	
	@Column(name="CODE_SEXE", nullable = true)
	@Label(value="Sexe")
	@TableValidatorFactory(factory = PersonneGenreValidatorFactory.class)
	@MultipleValue(factory=SexeRadioGroupFactory.class)
	private String codeSexe;
	
	@Column(name="NOM", nullable = false)
	@Label(value="Nom personne")
	private String nom;
	
	@Column(name="EMAIL", nullable = true, length=50)
	@Email
	@Label(value="Email personne")
	private String email;
	
	@Column(name="EMAIL_AUTRE", nullable = true, length=50)
	@FieldValidatorFactory(factory=RegExValiatorFactory.class, parameterList={@Parameter(name="expression",value="^([a-zA-Z0-9_.\\-+])+@(([a-zA-Z0-9\\-])+\\.)+[a-zA-Z0-9]{2,4}$")})
	@Label(value="Email autre")
	private String emailAutre;

	
	@Column(name="DATE_NAISSANCE", nullable = true)
	@Label(value="Date de naissance")
	private Date dateNaissance;
	
	
	@ManyToOne
	@JoinColumn(nullable = true, name = "SOCIETE_ID")
	@Label(value="Soci&eacute;t&eacute;")
	@DisplayValue(expression="${nom}")
	private Societe societe;

	public Integer getPersonneId()
	{
		return personneId;
	}

	public void setPersonneId(Integer personneId)
	{
		this.personneId = personneId;
	}

	public String getNom()
	{
		return nom;
	}

	public void setNom(String nom)
	{
		this.nom = nom;
	}

	public Societe getSociete()
	{
		return societe;
	}

	public void setSociete(Societe societe)
	{
		this.societe = societe;
	}
	
	
	public String getCodeCivilite()
	{
		return codeCivilite;
	}

	public void setCodeCivilite(String codeCivilite)
	{
		this.codeCivilite = codeCivilite;
	}

	@Override
	public int hashCode()
	{
		return personneId;
	}
	
	
	public String getCodeSexe()
	{
		return codeSexe;
	}

	public void setCodeSexe(String codeSexe)
	{
		this.codeSexe = codeSexe;
	}

	@Override
	public boolean equals(Object obj)
	{
		if (obj == null || !(obj instanceof Personne))
		{
			return false;
		}
		
		return personneId.equals(((Personne) obj).getPersonneId());
	}

	public String getEmail()
	{
		return email;
	}

	public void setEmail(String email)
	{
		this.email = email;
	}

	public Date getDateNaissance()
	{
		return dateNaissance;
	}

	public void setDateNaissance(Date dateNaissance)
	{
		this.dateNaissance = dateNaissance;
	}

	public String getEmailAutre()
	{
		return emailAutre;
	}

	public void setEmailAutre(String emailAutre)
	{
		this.emailAutre = emailAutre;
	}
	
	
	
}
